<?php

class Jd_users_model extends MY_Model {


    const USER = 'users';
    public $name;
    public $password;
    public $statu;
    public $group;
    public $gold;
    public $money;
    public $recommender;
    public $phone;
    public $channel;
    public $commission;
    public $team;


    public function __construct()
    {
        $this->modelename='Jd_users_model';
        $this->tablename='users';
        parent::__construct();
    }


    public function adduser($row){
        return $this->add($this->tablename,$row);
    }



    /**
     *  通过用户ID获取用户信息
     */
    public function GetUserById($uid=0,$select="*"){
          $result = $this->db->select($select)->from('users')->where("id=".$uid)->get()->result_array();
          return $result[0];
    }


    public function GetUserByName($username,$select="*"){
        $result = $this->db->select($select)->from('users')->where("username='$username'")->get()->result_array();
        if(empty($result)){
            return false;
        }

        return $result[0];
    }

    public function GetUserByPhone($phone,$select="*"){
        $result = $this->db->select($select)->from('users')->where("phone='$phone'")->get()->result_array();

        if(empty($result)){
            return false;
        }
        return $result[0];
    }


    /**
     *
     * 更新用户金币与金钱数据
     * @param $array
     * @return type
     */
    public  function  updata_user_money($sql,$user_id){
        $sql=$sql.' '."where id=".$user_id;
        return  $this->db->query($sql);
    }


    public function  updata_user($row){
        $user_id=$row['user_id'];
        unset($row['user_id']);
      return  $this->update($this->tablename,"id",$user_id,$row);
    }


    /**
     *
     * 根据用户组获取用户列表
     * @param $group
     * @param string $select
     * @return mixed
     */
    public function getuserbygroup($group,$select="*"){
       return   $result = $this->db->select($select)->from('users')->where("group=".$group)->get()->result_array();
    }















}
